<!DOCTYPE html>
<html class="zy-page" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/head :: header(~{::title},~{::link},~{::style})">
    <title></title>

</head>
<body class="zy-page">
<div class="zy-page-form">
    <div class="row">
        <div class="col-lg-7 col-lg-offset-2 col-sm-12">
            <form class="layui-form" action="" lay-filter="example">
                <input type="hidden" name="id" th:value="${userId}">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="text-danger">*</span> 新密码：</label>
                    <div class="layui-input-block">
                        <input type="password" id="password" name="password" lay-verify="required" autocomplete="off" placeholder="请输入新密码" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="text-danger">*</span> 确认密码：</label>
                    <div class="layui-input-block">
                        <input type="password" id="password2" name="password2" lay-verify="required" autocomplete="off" placeholder="请输入确认密码" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="text-danger">*</span> 手机号：</label>
                    <div class="layui-input-block">
                        <input type="number" name="phone" lay-verify="required|phone" autocomplete="off" placeholder="请输入手机号" class="layui-input">
                    </div>
                </div>


                <div class="form-actions zy-form-bottom-btn">
                    <div class="row">
                        <div class="col-sm-12 col-md-12">
                            <button class="btn btn-primary" lay-submit=""><i class="fa fa-save"></i>提交</button>
                        </div>
                    </div>
                </div>

            </form>
        </div>
    </div>

</div>


<div th:replace="common/htmlJS::common_js(~{::script})">
    <script th:inline="javascript">
        layui.config().extend({
            treeSelect: '{/}/plugins/treeSelect/treeSelect'
        });

        layui.use(['form'], function(){
            var form = layui.form
                ,layer = layui.layer;


            //自定义验证规则
            form.verify({
                phone: function(value){
                    if(value.length != 11){
                        return '手机号格式不正确';
                    }
                    var reg = /^1(3|4|5|6|7|8|9)\d{9}$/;
                    if(!reg.test(value)){
                        return '手机号格式不正确';
                    }
                }
            });

            //监听提交
            form.on('submit', function(data){
                var password = $("#password").val();
                var password2 = $("#password2").val();
                if(password != password2){
                    layer.msg('两次输入密码不一致，请重新输入', {icon: 2,shift: 6});
                    return false;
                }
                zy.ajaxJson({
                    url:basePath+"/system/user/resetPassword",
                    data:JSON.stringify(data.field),
                    success:function(result){
                        if (result.code == 200) {
                            layer.confirm('修改成功，重新登录系统！', {
                                title: "操作提示",
                                icon: 0,
                                btn: ['确认'],
                                btnAlign: "r",
                            }, function(index, layero){
                                parent.window.location.reload();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2,shift: 6});
                        }
                    }
                });
                return false;
            });

        });
    </script>
</div>
</body>
</html>